﻿@model Sharp.Web.Models.MasterDataIndexModel
@{
    var x = Html.X();
}

<script>
    function treeclick(view, record, item, index, e) {
        if (record.raw.FullName == "") {
            return false;
        }
        var store = Ext.getCmp("MasterGrid").getStore();
        store.proxy.extraParams = { assemblyQualifiedName: record.raw.FullName };
        store.load();
    }
    function treeSelectedValue() {
        var selected = Ext.getCmp("treeMasterData").getSelectionModel().getSelection();
        if (selected.length == 0) {
            return "";
        }
        return selected[0].raw.FullName;
    }
</script>

@(

 x.Panel().Layout(LayoutType.Border).Items(
            x.Panel()
                .Title("功能面板")
                .Region(Region.West)
                .Layout(LayoutType.Fit)
                .Width(225)
                .MinWidth(225)
                .MaxWidth(400)
                .Split(true)
                        .Collapsible(false).Items(x.TreePanel().ID("treeMasterData").RootVisible(false).HideHeaders(true).Animate(false).Root(Model.LeftTree)
                                                            .Listeners(l => l.ItemClick.Fn = "App.Main.treeclick")),
            x.Panel()
                .Title("分类")
                .Region(Region.Center)
                        .Layout(LayoutType.Fit)
                    .Split(true).Items(x.GridPanel().ID("MasterGrid")
                    .TopBar(x.Toolbar().Items(
                            x.Button().Text("浏览").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Details") + "',{assemblyQualifiedName:treeSelectedValue()});"),
                            x.Button().Text("新增").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Create") + "',{ShowOnly:true,assemblyQualifiedName:treeSelectedValue()});"),
                            x.Button().Text("修改").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Edit") + "',{assemblyQualifiedName:treeSelectedValue()});"),
                        x.Button().Text("删除").OnClientClick("App.Grid.OnModuleOperation(this,'" + Url.Action("Delete") + "',{IsAjax:true,assemblyQualifiedName:treeSelectedValue()});")
                        ,
                        new ToolbarFill(),
                        x.TextField().Width(300).FieldLabel("搜索").LabelWidth(50)
                            .Triggers(
                                x.FieldTrigger().Icon(TriggerIcon.Clear).HideTrigger(true),
                                x.FieldTrigger().Icon(TriggerIcon.Search)
                            )
                                .Listeners(ls => { ls.TriggerClick.Fn = "App.Main.searchFieldTriggerClick"; })
                        ))
                        .Store(x.StoreForModel().AutoLoad(false)
                            .Proxy(x.AjaxProxy().Url(Url.Action("GetPaged")).Reader(x.JsonReader().RootProperty("data")).ActionMethods(am => am.Read = HttpMethod.POST))
                            .RemoteSort(true).RemotePaging(true).PageSize(25)
                        .SorterFor(Model, m => m.Id, Ext.Net.SortDirection.DESC))
                    .SelectionModel(x.CheckboxSelectionModel())
                    .ColumnModel(
                        x.ColumnFor(m => m.Code),
                        x.ColumnFor(m => m.Name),
                        x.ColumnFor(m => m.Abbreviation),
                        x.ColumnFor(m => m.FullName)
                    )
                    .BottomBar(x.PagingToolbar().ItemsFromPartial("~/Views/Shared/_PagingToolbarPartial.cshtml"))
                    .EmptyText("无数据。")
                    .View(Html.X().GridView().StripeRows(true).TrackOver(true))
                        .Listeners(li => { li.ItemDblClick.Fn = "App.Grid.OnModuleGridItemDblClick"; }))
            )

)